<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="webroot" value="${pageContext.request.contextPath}" />
<html>
<head>
	<meta charset="utf-8">
	<title>操作日记列表</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${webroot}/static/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${webroot}/static/css/public.css" media="all" />
<style type="text/css">
.laytable-cell-checkbox, .laytable-cell-numbers, .laytable-cell-space {
    padding: 6px;
}
 .layui-btn+.layui-btn {
    margin-left: 0px;
}
</style>
</head>
<body class="childrenBody">
<form class="layui-form">
	<blockquote class="layui-elem-quote quoteBox">
		<form class="layui-form">
		<input type="hidden" id="roleName" value="${user.roleName}">
		    <label class="layui-form-label">操作人员:</label>
		    <div class="layui-input-inline">
			   <select id="userName">
				   <option value="">请选择</option>
			       <c:forEach items="${list}" var="l">		
			          <option value="${l.userName}">${l.userName}</option>
			       </c:forEach>
		       </select>
			</div>
			<div class="layui-inline">
			    <label class="layui-form-label">操作日期:</label>
				<div class="layui-input-inline">
                    <input type="text" class="layui-input" id="createTime" placeholder="请选择操作日期" lay-key="1">
                </div>
				<a class="layui-btn search_btn" data-type="reload">搜索</a>
				<a class="layui-btn layui-btn-primary reset" data-type="reload">重置</a>
			</div>
			<div class="layui-inline">
				<a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn">批量删除</a>
			</div>
		</form>
	</blockquote>
	<table id="newsList" lay-filter="newsList"></table>
</form>
<script type="text/javascript" src="${webroot}/static/layui/layui.js"></script>
<script src="${webroot}/static/js/jquery.min.js" charset="utf-8"></script>
<script>
layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;
   
    laydate.render({
        elem: '#createTime'
    });
    //新闻列表
    var tableIns = table.render({
        elem: '#newsList',
        url : '/admin/operation/querypage',
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limit : 15,
        limits : [ 10, 15, 20, 25 ,30 , 50, 80, 100],
        id : "newsListTable",
        cols : [[
            {type: "checkbox", fixed:"left",title: '全选'},
            {field: 'userName', title: '操作者', align:"center"},
            {field: 'position', title: '职位', align:"center"},
            {field : 'createTime', title : '添加时间', sort : false, fixed : false , align:"center", templet : function(d){return layui.laytpl.toDateString(d.createTime,'yyyy-MM-dd HH:mm:ss'); }},
            {field: 'ip', title: 'IP地址', align:'center'},
            {field: 'operationRecord', title: '操作记录', align:'center'}, 
        ]]
    });

    //是否置顶
    form.on('switch(newsTop)', function(data){
        var index = layer.msg('修改中，请稍候',{icon: 16,time:false,shade:0.8});
        setTimeout(function(){
            layer.close(index);
            if(data.elem.checked){
                layer.msg("置顶成功！");
            }else{
                layer.msg("取消置顶成功！");
            }
        },500);
    })

	form.on('select', function(data){
	  $("#roleId").val(data.value); //得到被选中的值]
	}); 
    
    //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
    $(".search_btn").on("click",function(){
         table.reload("newsListTable",{
              page: {
                    curr: 1 //重新从第 1 页开始
              },
              where: {
            	  userName: $("#userName").val(), //搜索的关键字
            	  createTime: $("#createTime").val()
              }
         });
    });
    
  //重置
    $(".reset").on("click",function(){
    	document.location.href="/admin/operation/showlist";
    	/* $("#createTime").val("");
        $("#userName").val("");
        form.render('select');
        table.reload("newsListTable",{
            page: {
                  curr: 1 //重新从第 1 页开始
            },
            where: {
            	  userName: '', //搜索的关键字
            	  createTime: ''
            }
       }); */
    });

    //批量删除
    $(".delAll_btn").click(function(){
    	if($("#roleName").val() != "超级管理员"){
    		return layer.msg("无批量删除操作权限");
		}
        var checkStatus = table.checkStatus('newsListTable'),
            data = checkStatus.data,
            id = [];
        if(data.length > 0) {
            for (var i in data) {
                id.push(data[i].id);
            }
            layer.confirm('确定删除选中的日志？', {icon: 3, title: '提示信息'}, function (index) {
                $.get("/admin/operation/delete",{
                     id : id.join(",")  //将需要删除的newsId作为参数传入
                },function(data){
                  layer.msg("删除成功");
              	  setTimeout(function(){tableIns.reload();},2000);
                  layer.close(index);
                })
            })
        }else{
            layer.msg("请选择需要删除的日志");
        }
    })

  	// 时间戳的处理
		layui.laytpl.toDateString = function(d, format) {
			var date = new Date(d || new Date()), ymd = [
					this.digit(date.getFullYear(), 4),
					this.digit(date.getMonth() + 1),
					this.digit(date.getDate()) ], hms = [
					this.digit(date.getHours()),
					this.digit(date.getMinutes()),
					this.digit(date.getSeconds()) ];

			return format.replace(/yyyy/g, ymd[0]).replace(/MM/g,
					ymd[1]).replace(/dd/g, ymd[2]).replace(/HH/g,
					hms[0]).replace(/mm/g, hms[1]).replace(/ss/g,
					hms[2]);
		};
		// 数字前置补零
		layui.laytpl.digit = function(num, length, end) {
			var str = '';
			num = String(num);
			length = length || 2;
			for (var i = num.length; i < length; i++) {
				str += '0';
			}
			return num < Math.pow(10, length) ? str + (num | 0)
					: num;
		};
    
	function roleAuthor(roleId){
		window.location.href="/admin/role/showsuthority?roleId="+roleId;
	}

})
</script>
</body>
</html>